<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>险种管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="insTypMgr" title="险种管理" lselected="true">
                <div class="searchArea">
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label">险种名称</div>
                                <div class="field">
                                    <input name="typNm" id="typNm" type="text" class="ui-textbox" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">险种类型</div>
                                <div class="field">
                                    <input name="typClsCd" id="typClsCd" data-value="" placeholder="请选择"
                                           ltype="combobox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">保险类型</div>
                                <div class="field">
                                    <input name="typPid" id="typPid" data-value="" placeholder="请选择"
                                           ltype="combobox">
                                </div>
                            </div>
                            <div class="clearFix"></div>
                            <div class="btnsBox">
                                <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                                <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                                <span id="addBtn" class="sq-button sq-button-round">新增</span>
                                <span id="changeBtn" class="sq-button sq-button-round">修改</span>
                                <span id="delBtn" class="sq-button sq-button-round">删除</span>
                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="ligergrid1" class="sq-grid"></div>
            </div>
            <div tabid="insTypCfg" title="险种配置">
                <iframe frameborder="0" name="insTypCfg" id="insTypCfg" src=""></iframe>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var grid = null;
    var pageInApp = {};
    var loadedTabs = [];
    $(function () {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                if (loadedTabs.indexOf(tabid) < 0) {
                    loadedTabs.push(tabid);
                    switch (tabid) {
                        case "insTypCfg":
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/insurance/insTypCfgR/toListPage.do");
                            break;
                    }
                }
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insTypInfo/selectTypList.do',
            method: 'get',
            columns: [
                {display: '险种名称', name: 'typNm', minWidth: 100, align: 'left'},
                {display: '险种类型', name: 'typClsCdNm', minWidth: 100, align: 'left'},
                {display: '是否默认显示', name: 'isDefVi', minWidth: 100, align: 'center', render: renderDefVi},
                {display: '是否系统内置', name: 'isSysDef', minWidth: 100, align: 'center', render: renderDefVi},
                {display: '险种标示', name: 'typNo', minWidth: 100, align: 'left'},
                {display: '险种费率', name: 'typRate', minWidth: 100, align: 'left'},
                {display: '备注', name: 'typRem', minWidth: 100, align: 'left'},
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            tree: {
                columnName: 'typNm',
                idField: 'id',
                parentIDField: 'typPid'
            }
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        var callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.SQopen({
                width: 550,
                height: 400,
                title: '新增险种',
                url: '<%=path%>/insurance/insTypInfo/toAddPage.do'
            });
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            $.ligerDialog.SQopen({
                width: 550,
                height: 400,
                title: '修改险种',
                url: '<%=path%>/insurance/insTypInfo/toModifyPage.do?id=' + _id
            });
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                if (selectedRows[index].isSysDef == 1) {
                    $.ligerDialog.SQalert({content: "系统内置险种无法删除", SQ_type: "warning"});
                    return;
                }
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM + "(此操作会删除选中险种下的所有子险种)", function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insTypInfo/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

        $("#typClsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("typClsCd").setData(${typClsCdList});
        $("#typPid").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("typPid").setData(${insTypCdList});


    });


    //格式化是否显示
    function renderDefVi(rowdata, index, value) {
        var defVi = "";
        if (null != value && 1 == value) {
            defVi = "是";
        } else {
            defVi = "否";
        }
        return defVi;
    }

</script>

</body>
</html>
